package com.keon.jianbao.ui.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.keon.jianbao.R;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by keon on 2015/9/2.
 */
public class EditTextLayout extends LinearLayout {
    @Bind(R.id.edit_text_label)
    TextView tvLable;
    @Bind(R.id.edit_text_content)
    LineEditText etContent;

    public EditTextLayout(Context context) {
        super(context);
    }

    public EditTextLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.layout_edit_text, this);
        ButterKnife.bind(this);
        init(context, attrs);
    }

    void init(Context context, AttributeSet attrs) {
        TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.EditTextLayout, 0, 0);
        String label = typedArray.getString(R.styleable.EditTextLayout_label);
        boolean showEditText = typedArray.getBoolean(R.styleable.EditTextLayout_showEditText, true);
        tvLable.setText(label);
        if (!showEditText) {
            etContent.setVisibility(GONE);
        }
    }

    public String getText() {
        return etContent.getText().toString();
    }

}
